var IndexPage = Ext.extend(Ext.Viewport, {
    top : new Ext.Panel({
        region : "north",
        id : "__nortPanel",
        contentEl : "app-header",
        height : 75
    }),
    center : null,
    west : new Ext.Panel({
        region : "west",
        id : "west-panel",
        title : "导航",
        iconCls : "menu-navigation",
        split : true,

        width : 208,
        layout : "accordion",
        collapsible : true,
        tools : [ {
            id : "refresh",
            handler : function() {
                if (curUserInfo.username == "admin") {
                    loadWestMenu("true");
                } else {
//                    loadWestMenu("true");
                    Ext.ux.Toast.msg("操作提示", "仅对开发用户开放刷新菜单功能!");
                }
            }
        } ],
        items : []
    }),
    south : new Ext.Panel({
        border : false,
        id : 'south-panel',
        region : "south",
        height : 28,
        border : false,
        bbar : [ {
            text : "退出系统",
            iconCls : "btn-logout",
            handler : function() {
                App.Logout();
            }
        },
        /*"-",
        {
            text : "在线用户",
            iconCls : "btn-onlineUser",
            handler : function() {
                OnlineUserSelector.getView()
                        .show();
            }
        },  */
        "-", {
            id : "messageTip",
            xtype : "button",
            hidden : true,
            width : 50,
            height : 20,
            handler : function() {
                var a = Ext.getCmp("messageTip");
                var b = Ext.getCmp("win");
                if (b == null) {
                    new MessageWin().show();
                }
                a.hide();
            }
        }, "->", {
            xtype : "tbfill"
        }, {
            xtype : "tbtext",
            text : "安全生产管理系统",
            id : "toolbarCompanyName"
        }, {
            xtype : "tbseparator"
        }, new Ext.Toolbar.TextItem('技术支持 <a href="http://www.xianzhixiang.com"  target="_blank">西安智翔软件科技控股有限公司</a>'), 
        	{
            xtype : "tbseparator"
        }, /*lpt 注释{
            pressed : false,
            text : "便签",
            iconCls : "tipsTile",
            handler : function() {
                App.clickTopTab("PersonalTipsView");
            }
        }, {
            xtype : "tbseparator"
        },*/ {
            pressed : false,
            text : "与我们联系",
            handler : function() {
                Ext.ux.Toast.msg("联系我们", "电话：029-89562002");
            }
        }, "-", {
            text : "收展头部",
            iconCls : "btn-expand",
            handler : function() {
                var a = Ext.getCmp("__nortPanel");
                if (a.collapsed) {
                    a.expand(true);
                } else {
                    a.collapse(true);
                }
            }
        },"-",
        {
            xtype : "combo",
            mode : "local",
            editable : false,
            value : "切换皮肤",
            width : 100,
            triggerAction : "all",
            store : [
                [ "ext-all"         , "缺省浅蓝"  ],
                [ "ext-all-css04"   , "灰白主题"  ],
                [ "ext-all-css05"   , "绿色主题"  ],
                [ "ext-all-css03"   , "粉红主题"  ],
                [ "xtheme-tp"       , "灰色主题"  ],
                [ "xtheme-default2" , "灰蓝主题"  ],
                [ "xtheme-default16","绿色主题"   ],
                [ "xtheme-newbluetheme","深蓝主题"],
                [ "xtheme-access"   ,"Access风格"] 
            ],
            listeners : {
                scope : this,
                "select" : function(d, b, c) {
                    if (d.value != "") {
                        var a = new Date();
                        a.setDate(a.getDate() + 300);
                        setCookie("theme",
                                d.value, a,
                                __ctxPath);
                        Ext.util.CSS.swapStyleSheet(
                                        "theme",
                                        __ctxPath+ "/resources/ext3/resources/css/" + d.value +  ".css");
                    }
                }
            }
        } ]
    }),
    constructor : function() {
        this.center = new Ext.TabPanel({
            id : "centerTabPanel",
            region : "center",
            deferredRender : true,
            enableTabScroll : true,
            activeTab : 0,
            defaults : {
                autoScroll : true,
                closable : true
            },
            //双击tab标题 最大化
           /* initEvents : function(){    
                Ext.TabPanel.superclass.initEvents.call(this);    
                this.on('add', this.onAdd, this, {target: this});    
                this.on('remove', this.onRemove, this, {target: this});    
                this.mon(this.strip, 'mousedown', this.onStripMouseDown, this);    
                this.mon(this.strip, 'contextmenu', this.onStripContextMenu, this);    
                if(this.enableTabScroll){    
                    this.mon(this.strip, 'mousewheel', this.onWheel, this);    
                }    
                //ADD:monitor title dbclick    
                this.mon(this.strip,'dblclick',this.onTitleDbClick,this);    
            },    
                     //ADD: handler    
            onTitleDbClick:function(e,target,o){    
                var t = this.findTargets(e);    
                if (t.item.fireEvent('beforeclose', t.item) !== false) {    
                            t.item.fireEvent('close', t.item);    
                            this.remove(t.item);                    
                       }    
            }, */   
            items : [],
            plugins : new Ext.ux.TabCloseMenu(),
            listeners : {
                "add" : function(d, b, c) {
                    if (d.items.length > 8) {
                        d.remove(d.items.get(0));
                        d.doLayout();
                    }
                }
            }
        });
        IndexPage.superclass.constructor.call(this, {
            border : false,
            layout : "border",
            items : [ this.top, this.west, this.center, this.south ],
            listeners : {
                afterrender :function(){
                    this.center.mon(this.center.header,'dblclick',function(){
                        var nortPanel = Ext.getCmp("__nortPanel");
                        var westpanel= Ext.getCmp("west-panel");
                        var southpanel= Ext.getCmp("south-panel");
                        if (nortPanel.collapsed) {
                            nortPanel.expand(true);
                            westpanel.expand(true);
                            southpanel.expand(true);
                        } else {
                            nortPanel.collapse(true);
                            westpanel.collapse(true);
                            southpanel.collapse(true);
                        }
                    });
                }
            }
        });
        var a = getCookie("_topNavId");
        if (a == null || a == undefined) {
            a = 0;
        }
        this.navTab = new Ext.TabPanel({
            //width : 600,
            id : "appNavTabPanel",
            deferredRender : true,
            enableTabScroll : true,
            activeTab : a,
            frame : false,
            border : false,
            plain : true,
            height : 0,
            renderTo : "header-nav",
            tabMargin : 20,
            defaults : {
                autoScroll : false,
                closable : false,
                bodyStyle : "padding-bottom: 12px;"
            },
            listeners : {
                scope : this,
                "tabchange" : function(d, c) {
                    var b = new Date();
                    b.setDate(b.getDate() + 300);
                    setCookie("_topNavId", c.getId(), b, __ctxPath);
                    loadWestMenu();
                }
            },
            items : []
        });
        this.afterPropertySet();
    },
    afterPropertySet : function() {
        var b = this.center;
        var d = function(g) {
            var e = Ext.getCmp("messageTip");
            var h = Ext.getCmp("win");
            var f = Ext.getCmp("wind");
            if (g > 0 && h == null && f == null) {
                e.setText('<div style="height:25px;"><img src="' + __ctxPath + '/resources/images/newpm.gif" style="height:12px;"/>你有<strong style="color: red;">' + g + "</strong>信息</div>");
                e.show();
            } else {
                e.hide();
            }
        };
        var c = function() {
            Ext.Ajax.request({
                url : __ctxPath + "/info/countInMessage.do",
                method : "POST",
                success : function(f, g) {
                    var e = Ext.util.JSON.decode(f.responseText);
                    count = e.count;
                    d(count);
                    setTimeout(c, 1000 * 60);
                },
                failure : function(e, f) {
                },
                scope : this
            });
        };
        var a = this.navTab;
        a.add(curUserInfo.topModules);
        setTimeout(function() {
            var e = getCookie("_topNavId");
            if (e) {
                a.activate(e);
            }
            if (a.getActiveTab() == null) {
                a.activate(a.items.get(0));
            }
            //                          c();
        }, 1200);
        Ext.getCmp("SearchForm").render("searchFormDisplay");
    }
});
function loadWestMenu(isReload) {
    if (!isReload) {
        isReload = "";
    }
    var westPanel = Ext.getCmp("west-panel");
    var topMenuId = Ext.getCmp("appNavTabPanel").getActiveTab().id;
    topMenuId = topMenuId.split("_")[1];
    Ext.Ajax.request({
        url : __ctxPath + "/panelTreeMenu.do?topMenuId=" + topMenuId + "&isReload=" + isReload,
        success : function(response, options) {
            var arr = Ext.decode(response.responseText).result;
            var __activedPanelId = getCookie("__activedPanelId");
            westPanel.removeAll();
            westPanel.doLayout();
            for (var i = 0; i < arr.length; i++) {
                var doc = strToDom(arr[i].subXml);
                var root = doc.documentElement || doc;
                var panel = new Ext.tree.TreePanel({
                    id : arr[i].id,
                    title : arr[i].text,
                    iconCls : arr[i].iconCls,
                    layout : "fit",
                    animate : true,
                    border : false,
                    autoScroll : true,
                    loader : new zhixiang.ux.TreeXmlLoader({
                        preloadChildren : true
                    }),
                    root : new Ext.tree.AsyncTreeNode({
                        text : root.tagName,
                        xmlNode : root
                    }),
                    listeners : {
                        "click" : App.clickNode
                    },
                    rootVisible : false
                });
                westPanel.add(panel);
                panel.on("expand", function(p) {
                    var expires = new Date();
                    expires.setDate(expires.getDate() + 30);
                    setCookie("__activedPanelId", p.id, expires, __ctxPath);
                });
                if (arr[i].id == __activedPanelId) {
                    westPanel.layout.activeItem = panel;
                }
            }
            westPanel.doLayout();
        }
    });
}